package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.InspectionData;
import com.ruoyi.mes.service.IInspectionDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡检数据管理Controller
 * 
 * @author ruoyi
 * @date 2025-01-09
 */
@RestController
@RequestMapping("/mes/data")
public class InspectionDataController extends BaseController
{
    @Autowired
    private IInspectionDataService inspectionDataService;

    /**
     * 查询巡检数据管理列表
     */
    @PreAuthorize("@ss.hasPermi('mes:data:list')")
    @GetMapping("/list")
    public TableDataInfo list(InspectionData inspectionData)
    {
        startPage();
        List<InspectionData> list = inspectionDataService.selectInspectionDataList(inspectionData);
        return getDataTable(list);
    }

    /**
     * 导出巡检数据管理列表
     */
    @PreAuthorize("@ss.hasPermi('mes:data:export')")
    @Log(title = "巡检数据管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InspectionData inspectionData)
    {
        List<InspectionData> list = inspectionDataService.selectInspectionDataList(inspectionData);
        ExcelUtil<InspectionData> util = new ExcelUtil<InspectionData>(InspectionData.class);
        util.exportExcel(response, list, "巡检数据管理数据");
    }

    /**
     * 获取巡检数据管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:data:query')")
    @GetMapping(value = "/{inspectionId}")
    public AjaxResult getInfo(@PathVariable("inspectionId") Long inspectionId)
    {
        return success(inspectionDataService.selectInspectionDataByInspectionId(inspectionId));
    }

    /**
     * 新增巡检数据管理
     */
    @PreAuthorize("@ss.hasPermi('mes:data:add')")
    @Log(title = "巡检数据管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InspectionData inspectionData)
    {
        return toAjax(inspectionDataService.insertInspectionData(inspectionData));
    }

    /**
     * 修改巡检数据管理
     */
    @PreAuthorize("@ss.hasPermi('mes:data:edit')")
    @Log(title = "巡检数据管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InspectionData inspectionData)
    {
        return toAjax(inspectionDataService.updateInspectionData(inspectionData));
    }

    /**
     * 删除巡检数据管理
     */
    @PreAuthorize("@ss.hasPermi('mes:data:remove')")
    @Log(title = "巡检数据管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{inspectionIds}")
    public AjaxResult remove(@PathVariable Long[] inspectionIds)
    {
        return toAjax(inspectionDataService.deleteInspectionDataByInspectionIds(inspectionIds));
    }
}
